home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / wc_Scale.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  8.2 KB  |  223 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         wc_Scale.c
  5. * RCS:          $Header: wc_Scale.c,v 1.3 91/03/14 03:15:06 mayer Exp $
  6. * Description:  XM_SCALE_WIDGET_CLASS
  7. * Author:       Niels Mayer, HPLabs
  8. * Created:      Sat Oct 28 04:32:59 1989
  9. * Modified:     Thu Oct  3 23:40:58 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: wc_Scale.c,v 1.3 91/03/14 03:15:06 mayer Exp $";
  42.  
  43.  
  44. #include <stdio.h>
  45. #include <Xm/Xm.h>
  46. #include <Xm/Scale.h>
  47. #include "winterp.h"
  48. #include "user_prefs.h"
  49. #include "xlisp/xlisp.h"
  50. #include "w_funtab.h"
  51.  
  52. extern Widget Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(); /* w_classes.c */
  53.  
  54.  
  55. /******************************************************************************
  56.  * typedef struct 
  57.  * {
  58.  *    int reason;
  59.  *    XEvent * event;
  60.  *    int value;
  61.  * } XmScaleCallbackStruct;
  62.  ******************************************************************************/
  63. static void Lexical_Bindings_For_XmScaleCallbackStruct(bindings_list, lexical_env, cd, o_widget)
  64.      LVAL bindings_list;    /* a list of symbols to which values from XmScaleCallbackStruct are bound */
  65.      LVAL lexical_env;        
  66.      XmScaleCallbackStruct* cd;
  67.      LVAL o_widget;        /* XLTYPE_WIDGETOBJ */
  68. {
  69.   extern LVAL s_CALLBACK_WIDGET, s_CALLBACK_REASON, s_CALLBACK_XEVENT, s_CALLBACK_VALUE; /* w_callbacks.c */
  70.   extern LVAL Wcb_Get_Callback_Reason_Symbol();    /* w_callbacks.c */
  71.   register LVAL s_bindname;
  72.  
  73.   for ( ; consp(bindings_list); bindings_list = cdr(bindings_list)) {
  74.  
  75.     s_bindname = car(bindings_list);
  76.  
  77.     if (s_bindname == s_CALLBACK_WIDGET) {
  78.       xlpbind(s_bindname, o_widget, lexical_env);
  79.     }
  80.     else if (s_bindname == s_CALLBACK_REASON) {
  81.       xlpbind(s_bindname, Wcb_Get_Callback_Reason_Symbol(cd->reason), lexical_env);
  82.     }
  83.     else if (s_bindname == s_CALLBACK_XEVENT) {
  84.       xlpbind(s_bindname, (cd->event) ? cv_xevent(cd->event) : NIL, lexical_env);
  85.     }
  86.     else if (s_bindname == s_CALLBACK_VALUE) {
  87.       xlpbind(s_bindname, cvfixnum((FIXTYPE) cd->value), lexical_env);
  88.     }
  89.     else {
  90.       extern char temptext[];    /* from winterp.c */
  91.       sprintf(temptext,
  92.           "Unknown binding name in XmScaleCallbackStruct callback evaluator. Valid symbols are [%s %s %s %s].",
  93.           (char*) getstring(getpname(s_CALLBACK_WIDGET)),
  94.           (char*) getstring(getpname(s_CALLBACK_REASON)),
  95.           (char*) getstring(getpname(s_CALLBACK_XEVENT)),
  96.           (char*) getstring(getpname(s_CALLBACK_VALUE)));
  97.       xlerror(temptext, s_bindname);
  98.     }
  99.   }
  100. }
  101.  
  102.  
  103. /******************************************************************************
  104.  * This is called indirectly via XtAddCallback() for callbacks returning
  105.  * an XmScaleCallbackStruct as call_data.
  106.  ******************************************************************************/
  107. static void XmScaleCallbackStruct_Callbackproc(widget, client_data, call_data)
  108.      Widget    widget;
  109.      XtPointer client_data;
  110.      XtPointer call_data;
  111. {
  112.   extern void Wcb_Meta_Callbackproc();    /* w_callbacks.c */
  113.  
  114.   Wcb_Meta_Callbackproc(client_data, call_data,
  115.             Lexical_Bindings_For_XmScaleCallbackStruct,
  116.             NULL);
  117. }
  118.  
  119. /******************************************************************************
  120.  * Same as WIDGET_CLASS's :add_callback method except that this understands
  121.  * how to get values from the XmScaleCallbackStruct.
  122.  * Specifying one or more of the following symbols in the callback bindings 
  123.  * list will bind that symbol's value in the lexical environment of the callback:
  124.  * CALLBACK_WIDGET
  125.  * CALLBACK_REASON
  126.  * CALLBACK_XEVENT
  127.  * CALLBACK_VALUE
  128.  ******************************************************************************/
  129. LVAL Xm_Scale_Widget_Class_Method_ADD_CALLBACK()
  130. {
  131.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  132.  
  133.   return (Wcb_Meta_Method_Add_Callback(XmScaleCallbackStruct_Callbackproc, FALSE));
  134. }
  135.  
  136.  
  137. /******************************************************************************
  138.  * Same as WIDGET_CLASS's :set_callback method except that this understands
  139.  * how to get values from the XmScaleCallbackStruct.
  140.  * Specifying one or more of the following symbols in the callback bindings 
  141.  * list will bind that symbol's value in the lexical environment of the callback:
  142.  * CALLBACK_WIDGET
  143.  * CALLBACK_REASON
  144.  * CALLBACK_XEVENT
  145.  * CALLBACK_VALUE
  146.  ******************************************************************************/
  147. LVAL Xm_Scale_Widget_Class_Method_SET_CALLBACK()
  148. {
  149.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  150.  
  151.   return (Wcb_Meta_Method_Add_Callback(XmScaleCallbackStruct_Callbackproc, TRUE));
  152. }
  153.  
  154. /******************************************************************************
  155.  * (send <scale_widget> :SET_VALUE <value>) --> rets <scale_widget>
  156.  * 
  157.  * void XmScaleSetValue (w, value)
  158.  * Widget w;
  159.  * int    value;
  160.  ******************************************************************************/
  161. LVAL Xm_Scale_Widget_Class_Method_SET_VALUE()
  162. {
  163.   LVAL self;
  164.   Widget widget_id;
  165.   int value;
  166.  
  167.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  168.   value = (int) getfixnum(xlgafixnum());
  169.   xllastarg();
  170.  
  171.   XmScaleSetValue(widget_id, value);
  172.  
  173.   return (self);
  174. }
  175.  
  176. /******************************************************************************
  177.  * (send <scale_widget> :GET_VALUE) --> returns slider value as a FIXNUM
  178.  * 
  179.  * void XmScaleGetValue (w, value)
  180.  * Widget w;
  181.  * int * value;
  182.  ******************************************************************************/
  183. LVAL Xm_Scale_Widget_Class_Method_GET_VALUE()
  184. {
  185.   LVAL self;
  186.   Widget widget_id;
  187.   int value;
  188.  
  189.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  190.   xllastarg();
  191.  
  192.   XmScaleGetValue(widget_id, &value);
  193.  
  194.   return (cvfixnum((FIXTYPE) value));
  195. }
  196.  
  197. /******************************************************************************
  198.  *
  199.  ******************************************************************************/
  200. Wc_Scale_Init()
  201. {
  202.   LVAL o_XM_SCALE_WIDGET_CLASS;
  203.   extern LVAL Wcls_Create_Subclass_Of_WIDGET_CLASS(); /* w_classes.c */
  204.   extern      xladdmsg();    /* from xlobj.c */
  205.  
  206.   o_XM_SCALE_WIDGET_CLASS =
  207.     Wcls_Create_Subclass_Of_WIDGET_CLASS("XM_SCALE_WIDGET_CLASS",
  208.                      xmScaleWidgetClass);
  209.  
  210.   xladdmsg(o_XM_SCALE_WIDGET_CLASS, ":ADD_CALLBACK",
  211.            FTAB_Xm_Scale_Widget_Class_Method_ADD_CALLBACK);
  212.  
  213.   xladdmsg(o_XM_SCALE_WIDGET_CLASS, ":SET_CALLBACK",
  214.            FTAB_Xm_Scale_Widget_Class_Method_SET_CALLBACK);
  215.  
  216.   xladdmsg(o_XM_SCALE_WIDGET_CLASS, ":SET_VALUE",
  217.        FTAB_Xm_Scale_Widget_Class_Method_SET_VALUE);
  218.  
  219.   xladdmsg(o_XM_SCALE_WIDGET_CLASS, ":GET_VALUE",
  220.        FTAB_Xm_Scale_Widget_Class_Method_GET_VALUE);
  221. }
  222.